package com.orientsec.autotest.project.system.systemType.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.systemType.domain.SystemType;
import com.orientsec.autotest.project.system.systemType.service.ISystemTypeService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 系统环境配置信息操作处理
 * 
 * @author autotest
 * @date 2019-12-18
 */
@Controller
@RequestMapping("/system/systemType")
public class SystemTypeController extends BaseController
{
    private String prefix = "system/systemType";
	
	@Autowired
	private ISystemTypeService systemTypeService;
	
	@RequiresPermissions("system:systemType:view")
	@GetMapping()
	public String systemType()
	{
	    return prefix + "/systemType";
	}
	
	/**
	 * 查询系统环境配置列表
	 */
	@RequiresPermissions("system:systemType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SystemType systemType)
	{
		startPage();
        List<SystemType> list = systemTypeService.selectSystemTypeList(systemType);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出系统环境配置列表
	 */
	@RequiresPermissions("system:systemType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SystemType systemType)
    {
    	List<SystemType> list = systemTypeService.selectSystemTypeList(systemType);
        ExcelUtil<SystemType> util = new ExcelUtil<SystemType>(SystemType.class);
        return util.exportExcel(list, "systemType");
    }
	
	/**
	 * 新增系统环境配置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存系统环境配置
	 */
	@RequiresPermissions("system:systemType:add")
	@Log(title = "系统环境配置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SystemType systemType)
	{		
		return toAjax(systemTypeService.insertSystemType(systemType));
	}

	/**
	 * 修改系统环境配置
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		SystemType systemType = systemTypeService.selectSystemTypeById(id);
		mmap.put("systemType", systemType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存系统环境配置
	 */
	@RequiresPermissions("system:systemType:edit")
	@Log(title = "系统环境配置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SystemType systemType)
	{		
		return toAjax(systemTypeService.updateSystemType(systemType));
	}
	
	/**
	 * 删除系统环境配置
	 */
	@RequiresPermissions("system:systemType:remove")
	@Log(title = "系统环境配置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(systemTypeService.deleteSystemTypeByIds(ids));
	}
	
}
